if (!johnny) { var johnny = {}; };
$.extend(true, johnny, {
    formEditable: {
        text: function (value, id, name) {
            var form = $("<form data-id=" + id + "/>").css({ margin: 0, padding: 0 });
            var input = $("<input/>").attr({
                "type": "text",
                "name": name,
                "value" : value
            }).addClass("textEditable " + name);
            input.appendTo(form);
            return form.get(0).outerHTML;
        },
        checkbox: function (value, id, name) {
            var form = $("<form data-id=" + id + "/>").css({ margin: 0, padding: 0 });
            var checkbox = $("<input>").attr({
                "type": "checkbox",
                "name": name,
                "value": value,
            }).addClass("checkboxEditable " + name);
            if (value) {
                checkbox.attr("checked", "checked");
            }
            form.html(checkbox);
            return form.get(0).outerHTML;
        }
    },
    textEditable: function (selector, url, updateSuccess) {
          var beforeValue;
       
        $(selector).focus(function () {
            beforeValue = $(this).val();
         }).blur(function () {
             var afterValue = $(this).val();
            //check if it is positive decimal value
                 if (beforeValue != afterValue) {
                    var form = $(this).closest("form");
                    var updatedRow = $(this).closest("tr");
                    $.ajax({
                        type: "POST",
                        dataType: "json",
                        url: url + form.attr("data-id")+"/",
                        data: form.serialize(),
                        success: function (data) {
                            updateSuccess(data, updatedRow);
                        }
                    });
                }
             
        }).keypress(function (e) {
            //ignore if Enter
            if (e.keyCode == 13) {
                e.preventDefault();
                e.stopPropagation();
            }
        });
    },
    checkboxEditable: function (inputObj, url, updateSuccess) {
        $(inputObj).click(function () {
            var checked = $(this).attr("checked");
            $(this).attr({
                value: (checked) ? "true" : "false",
            });
            var form = $(this).closest("form");
            var updatedRow = $(this).closest("tr");
            $.ajax({
                type: "POST",
                dataType: "json",
                url: url + form.attr("data-id"),
                data: $(this).attr("name") + "=" + $(this).val(),//form.serialize(),
                success: function (data) {
                    updateSuccess(data, updatedRow);
                }
            });
        });
    }
});